#include "MsgNode.h"
#include "boost/asio.hpp"


RecvMsgNode::RecvMsgNode(short max_len,short msg_id)
:MsgNode(max_len),_msg_id(msg_id)
{

}


SendMsgNode::SendMsgNode(const char* msg, short max_len,short msg_id)
:MsgNode(HEAD_TOTAL_LEN+max_len),_msg_id(msg_id)
{
    //将数据复制到MsgNode的_data中
    //记得转换网络字节序
    short network_id = boost::asio::detail::socket_ops::host_to_network_short(msg_id);
    short network_len = boost::asio::detail::socket_ops::host_to_network_short(max_len);
    memcpy(_data,&network_id,HEAD_ID_LEN);
    memcpy(_data+HEAD_ID_LEN,&network_len,HEAD_DATA_LEN);
    memcpy(_data+HEAD_TOTAL_LEN,msg,max_len);
}